<!--广告类型 -->
<template>
  <div class="table">
    <SearchTable v-model:formStatus="formStatus" ref="searchTableRef" @handleViewEdit="handleViewEdit" />
    <FormDialog v-model:formStatus="formStatus" v-model:form="advertisingTypeForm" @handleSuccess="handleSuccess" />
  </div>
</template>

<script setup lang="ts" name="advertisingType">
import SearchTable from "@/components/advertisingManager/advertisingType/SearchTable.vue";
import FormDialog from "@/components/advertisingManager/advertisingType/FormDialog.vue";
import type { ViewMode, ViewModeFilter } from "@/types/common";
import type { IAdvertisingType } from "@/types/advertisingType";
/* 表格子组件的引用 */
const searchTableRef = useTemplateRef("searchTableRef");
const formStatus = ref<ViewMode>("none");
const advertisingTypeForm = reactive<IAdvertisingType>({
  id: 0,
  type_name: "",
  banner_link: "",
  sort: 0
});
/* 点击编辑按钮 */
function handleViewEdit(row: IAdvertisingType, code: ViewModeFilter) {
  formStatus.value = code;
  nextTick(() => {
    advertisingTypeForm.id = row.id;
    advertisingTypeForm.type_name = row.type_name;
    advertisingTypeForm.sort = row.sort;
    advertisingTypeForm.banner_link = row.banner_link;
  });
}
/* 成功保存或者编辑的回调 */
function handleSuccess() {
  searchTableRef.value?.getTableInfo();
}
</script>

<style scoped></style>
